#include <stdio.h>
#include <stdbool.h>

#define ElementType int
#define Size 20

struct Queue
{
    ElementType arr[Size];
    int front;
    int rear;
    int len;
};
typedef struct Queue queue;

void InitQueue(queue *q)
{
    q->front = -1;
    q->rear = 0;
    q->len = 0;
}

void QPush(queue *q, ElementType value)
{
    if (q->len == Size)
    {
        printf("queue not en");
    }
    
    q->arr[q->rear] = value;
    q->rear = (q->rear + 1) % Size;
    q->len++;
}

void QPop(queue *q)
{
    if (q->len == 0)
    {
        printf("queue empty!\n");
        return;
    }
    q->front = (q->front + 1) % Size;
    q->len--;
}

ElementType* GetQueueFont(queue *q)
{
    if (q->len == 0)
    {
        return NULL;
    }
    return &q->arr[(q->front+1) % Size];
}

bool IsQueueEmpty(queue *q)
{
    return q->len == 0;
}

int main()
{
    queue q;
    InitQueue(&q);

    for (int i = 0; i < 13; i++)
    {
        QPush(&q, i+1);
    }

    int count = 0;

    while (q.len != 1)
    {
        count++;
        ElementType v = *GetQueueFont(&q);
        QPop(&q);
        if (count == 3)
        {
            printf("die %d!\n", *GetQueueFont(&q));
            count = 0;
        }
        else
        {
            QPush(&q, v);
        }
    }
    printf("%d live!\n", *GetQueueFont(&q));
    return 0;
}